<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>充值</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="/zhenze/Public/home/css/reset.css" />
		<link rel="stylesheet" href="/zhenze/Public/home/css/chongzhi.css" />
		<link rel="stylesheet" href="/zhenze/Public/home/css/font-awesome.min.css" />
	</head>

	<body>
		<div class="top">
			<a href="javascript:history.go(-1);"><i class="fa fa-angle-left"></i></a>
			<p>充值</p>
		</div>
		<div class="cont">
			<form id="form1">
				<input type="text" placeholder="请输入充值金额" id="jine" name="jine" onkeyup='this.value=this.value.replace(/\D/gi,"")' maxlength="5" />
				<input type="tel" placeholder="请输入电话号码" id="tel" name="tel" onkeyup='this.value=this.value.replace(/\D/gi,"")' maxlength="11" />
				<input type="text" id="submit" name="money" style="display: none;" />
			</form>
		</div>
		<div class="cont1">
			<h1>面值</h1>
			<ul>
				<?php if(is_array($buylist)): $i = 0; $__LIST__ = $buylist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$data): $mod = ($i % 2 );++$i;?><li data="<?php echo (str_replace('.00','',$data["buy_money"])); ?>"><?php echo (str_replace('.00','',$data["buy_money"])); ?>元</li><?php endforeach; endif; else: echo "" ;endif; ?>
				<div class="clear"></div>
			</ul>
		</div>
		<p class="px">即时充值，享受95折优惠哦！</p>
		<div class="cont2">
			<ul>
				<li>
					<img style="margin-left: 0.25rem; margin-right: 0.8rem;" src="/zhenze/Public/home/img/money.png" />
					<p style="margin-right: 5.75rem;">我的佣金</p>
					<p><?php echo ($balance["money"]); ?>元</p>
					<img id="img1" src="/zhenze/Public/home/img/true.png" />
					<div class="clear"></div>
				</li>
				<li>
					<img style="margin-right: 0.5rem;" src="/zhenze/Public/home/img/webkit.png" />
					<p>微信支付</p>
					<img id="img2" src="/zhenze/Public/home/img/false.png" />
					<div class="clear"></div>
				</li>
			</ul>
		</div>
		<button id="chongzhi">充值</button>
		<script type="text/javascript" src="/zhenze/Public/home/js/jquery-3.1.1.min.js"></script>
		<script src="/zhenze/Public/home/js/screenSize.js" type="text/javascript" charset="utf-8"></script>
		<script>
			var isvip=<?php echo ($isvip); ?>;
			$(function() {
				var zhifutype = 0; //余额支付为0，微信支付为1
				$('#img1').click(function() {
					$("#img1").attr('src', '/zhenze/Public/home/img/true.png');
					$("#img2").attr('src', '/zhenze/Public/home/img/false.png');
					zhifutype = 0;
					return zhifutype;
				});
				$('#img2').click(function() {
					$("#img1").attr('src', '/zhenze/Public/home/img/false.png');
					$("#img2").attr('src', '/zhenze/Public/home/img/true.png');
					zhifutype = 1;
					return zhifutype;
				})
				$('#jine').change(function() {
					$('.cont1 li').css("border-color", "#0195FF");
					// alert($('#jine').val());
					$('#submit').val($('#jine').val() + "元");
					//95折展示
					var showmoney=parseFloat($('#jine').val())*0.95;
					$("#chongzhi").html("充值，需付"+showmoney.toFixed(2) + "元");
					// }
				})
				$('.cont1 li').each(function(e){
					$(this).click(function(){
						$('.cont1 li').css("border-color", "#0195FF");
						$(this).css("border-color", "red");
						//alert($(this).attr("data"));
						$('#submit').val($(this).attr("data") + "元");
						var showmoney=parseFloat($(this).attr("data"))*0.95;
						$("#chongzhi").html("充值，需付"+ showmoney.toFixed(2)+ "元");
						$('#jine').val(''); //选择固定套餐时把自由输入金额置空						
					});
				});

				$('#chongzhi').click(function() {
					if(isvip==0){ //非会员跳转
						location.href="<?php echo U('index/topupno');?>";
						return false;
					}
					if($('#submit').val() == "" || $('#tel').val() == "" || $('#tel').val().length!=11) {
						//如果没有选择充值金额，提示选择
						alert('请将信息补充完整');
						return false;
					}
					//alert(zhifutype);
					if(zhifutype == 0) {
						//余额支付，验证余额是否充足
						var yongjin = "<?php echo ($balance['money']); ?>";
						var money_1 = $('#submit').val();
						var money_2 = parseInt(money_1.substring(0, money_1.length - 1));
						//alert(money_2 + '输入额');
						//alert(yongjin + '佣金');
						if((money_2 > yongjin) || (yongjin <= 0)) {
							alert("余额不足，请使用其他支付方式");
							return false;
						} else {
							//alert("可以支付")
							$.ajax({
								type: "post",
								url: "<?php echo U('index/chongzhi');?>",
								data: {
									mobile: $("#tel").val(),
									amount: $("#submit").val()
								},
								success: function(data) {
									if(data.flag==1){
										alert("充值操作成功");
										location.href="<?php echo U('index/topuplist');?>";
									}else{
										alert("充值操作失败");
										location.href="<?php echo U('index/topup');?>";
									}
								},
								error: function(data) {
									//console.log(data)
									alert("网络请求失败");
									location.href="<?php echo U('index/topup');?>";
								}
							})
						}
					} else {
						//微信支付
						alert("暂不支持");
						/*
						var amount=$('#submit').val();
						var mobile=$('#tel').val();
						location.href="<?php echo U('index/weixinpay');?>&mobile="+mobile+"&amount="+amount;
						*/
					}

				})

			})
		</script>
	</body>

</html>